﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Kardex.Modify;

namespace University.Workshop.Presentation.Kardex.Modify
{
    /// <summary>
    /// Interaction logic for PageFirstModifyKardexView.xaml
    /// </summary>
    public partial class PageFirstModifyKardexView : Page,IFirstStepForModifyKardex
    {
        private PresenterModifyKardexView pInternal;
        private Presenters.Kardex.Modify.PresenterFirstStepForModifyKardex pFirstStepForModifyKardex;
        public PageFirstModifyKardexView(PresenterModifyKardexView pExternal)
        {
            InitializeComponent();
            pInternal = pExternal;
            pFirstStepForModifyKardex= new PresenterFirstStepForModifyKardex(this);
        }

        private void PersonCiTxt_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
        }

        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Cut)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }

        private void PersonPhonesTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {

        }

        private void PersonPhonesTxt_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {

        }

        private void PersonPhonesTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsDigit(ch) || ch.Equals(','));
            }
        }

        private void PersonPhonesTxt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
        }

        private void PersonLastNamesTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {

            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !char.IsLetter(ch);
            }
        }

        public string PersonId
        {
            set
            {
                PersonCiTxt.Text = value;
            }
        }

        public string PersonNames
        {
            get
            {
                return PersonNamesTxt.Text;
            }
            set
            {
                PersonNamesTxt.Text = value;
            }
        }

        public string PersonLastNames
        {
            get
            {
                return PersonLastNamesTxt.Text;
            }
            set
            {
                PersonLastNamesTxt.Text = value;
            }
        }

        public string PersonNewPhones
        {
            get
            {
                return PersonPhonesTxt.Text;
            }
            set
            {
                PersonPhonesTxt.Text = value;
            }
        }

        public List<string> PersonPhones
        {
            set { PersonPhonesList.ItemsSource = value; }
        }

        public Model.Kardex KardexToModify
        {
            get;
            set;
        }

        public void Update()
        {
            pFirstStepForModifyKardex.UpdatePersonData();
        }


        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MessageBox.Show(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MessageBox.Show(value);
            }
        }

        public void ChargeDataToBasic()
        {
            pFirstStepForModifyKardex.ChargeDataKardexPersonData();
        }

        public void GoNextPage()
        {
        }

        public void GoBackPage()
        {
            pInternal.GoStepOne();

        }


        private void PersonPhonesTxt_TextChanged(object sender, TextChangedEventArgs e)
        {
            pFirstStepForModifyKardex.ChargePhonesToList();
        }
    }
}
